package com.breeze.blockchain.controller.admin;

import com.breeze.blockchain.mybatis.entity.OperationLogDo;
import com.breeze.blockchain.service.OperationLogService;
import com.breeze.components.web.core.ResponseDTO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 操作日志记录 控制层。
 *
 * @author breeze
 * @since 2024-05-11 23:21:51
 */
@RestController
@Tag(name = "操作日志记录接口")
@RequestMapping("api/admin/operationLog")
public class OperationLogController {

  @Resource private OperationLogService operationLogService;

  /**
   * 添加操作日志记录。
   *
   * @param operationLogDo 操作日志记录
   */
  @PostMapping("save")
  @Operation(summary = "保存操作日志记录")
  public ResponseDTO<Void> save(
      @RequestBody @Parameter(name = "操作日志记录") OperationLogDo operationLogDo) {
    operationLogService.save(operationLogDo);
    return ResponseDTO.ok();
  }

  /**
   * 根据主键删除操作日志记录。
   *
   * @param id 主键
   */
  @GetMapping("remove/{id}")
  @Operation(summary = "根据主键操作日志记录")
  public ResponseDTO<Void> remove(@PathVariable @Parameter(name = "操作日志记录主键") Serializable id) {
    operationLogService.removeById(id);
    return ResponseDTO.ok();
  }

  /**
   * 根据主键更新操作日志记录。
   *
   * @param operationLogDo 操作日志记录
   */
  @PostMapping("update")
  @Operation(summary = "根据主键更新操作日志记录")
  public ResponseDTO<Void> update(
      @RequestBody @Parameter(name = "操作日志记录主键") OperationLogDo operationLogDo) {
    operationLogService.updateById(operationLogDo);
    return ResponseDTO.ok();
  }

  /**
   * 查询所有操作日志记录。
   *
   * @return 所有数据
   */
  @GetMapping("list")
  @Operation(summary = "查询所有操作日志记录")
  public ResponseDTO<List<OperationLogDo>> list() {
    return ResponseDTO.ok(operationLogService.list());
  }

  /**
   * 根据操作日志记录主键获取详细信息。
   *
   * @param id 操作日志记录主键
   * @return 操作日志记录详情
   */
  @GetMapping("getInfo/{id}")
  @Operation(summary = "根据主键获取操作日志记录")
  public ResponseDTO<OperationLogDo> getInfo(@PathVariable Serializable id) {
    return ResponseDTO.ok(operationLogService.getById(id));
  }

  /**
   * 分页查询操作日志记录。
   *
   * @param page 分页对象
   * @return 分页对象
   */
  @GetMapping("page")
  @Operation(summary = "分页查询操作日志记录")
  public ResponseDTO<Page<OperationLogDo>> page(
      @Parameter(name = "分页信息") Page<OperationLogDo> page,
      @Parameter(name = "操作日志记录") OperationLogDo operationLogDo) {
    return ResponseDTO.ok(operationLogService.page(page, QueryWrapper.create(operationLogDo)));
  }
}
